package com.enzo.prms.common.taglib;

import java.io.IOException;
import java.text.SimpleDateFormat;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang.StringUtils;

import com.enzo.prms.common.util.DateUtil;


public class DateTagNoBody extends TagSupport {
	private static final long serialVersionUID = 6367461999254979410L;
	private static final String DEFAULT_PATTERN = "yyyy-MM-dd";
	private String pattern;

	@Override
	public int doStartTag() throws JspException {
		pattern = StringUtils.isNotEmpty(pattern) ? pattern : DEFAULT_PATTERN;
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		String today = sdf.format(DateUtil.getDate());
		JspWriter out = pageContext.getOut();
		try {
			out.print(today);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return Tag.SKIP_BODY;
	}

	public void setPattern(String pattern) {
		this.pattern = pattern;
	}

}
